package com.mythesis.bpel.ui.client;

import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.StackPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mythesis.bpel.ui.client.controls.BpelComponentControl;
import com.mythesis.bpel.ui.client.controls.BpelContainerControl;
import com.mythesis.bpel.ui.client.controls.BpelControl;

public class BpelPalette extends StackPanel {
	protected PickupDragController dragController;
	protected BpelControl[] actions;
	protected BpelControl[] controls;
	protected BpelControl[] faults;
	
	protected BpelItemsGroup actionGroup;
	protected BpelItemsGroup controlGroup;
	protected BpelItemsGroup faultGroup;

	protected void initPaletteItems(){
		actions = new BpelControl[] {
			new BpelComponentControl(new Image("images/actions/empty.gif"), new Label("Empty")),
			new BpelComponentControl(new Image("images/actions/invoke.gif"), new Label("Invoke")),
			new BpelComponentControl(new Image("images/actions/receive.gif"), new Label("Receive")),
			new BpelComponentControl(new Image("images/actions/reply.gif"), new Label("Reply")),
			new BpelComponentControl(new Image("images/actions/assign.gif"), new Label("Assign")),
			new BpelComponentControl(new Image("images/actions/validate.gif"), new Label("Validate"))	
		};
		
		controls = new BpelControl[] {
			new BpelContainerControl(new Image("images/controls/if.gif"), new Label("If")),
			new BpelContainerControl(new Image("images/controls/pick.gif"), new Label("Pick")),
			new BpelContainerControl(new Image("images/controls/while.gif"), new Label("While")),
			new BpelContainerControl(new Image("images/controls/foreach.gif"), new Label("For Each")),
			new BpelContainerControl(new Image("images/controls/repeatuntil.gif"), new Label("Repeat Until")),
			new BpelContainerControl(new Image("images/controls/wait.gif"), new Label("Wait")),
			new BpelContainerControl(new Image("images/controls/sequence.gif"), new Label("Sequence")),
			new BpelContainerControl(new Image("images/controls/scope.gif"), new Label("Scope")),
			new BpelContainerControl(new Image("images/controls/flow.gif"), new Label("Flow"))
		};
		
		faults = new BpelControl[] {
			new BpelComponentControl(new Image("images/faults/exit.gif"), new Label("Exit")),
			new BpelComponentControl(new Image("images/faults/throw.gif"), new Label("Throw")),
			new BpelComponentControl(new Image("images/faults/rethrow.gif"), new Label("Rethrow")),
			new BpelComponentControl(new Image("images/faults/compensate.gif"), new Label("Compensate")),
			new BpelComponentControl(new Image("images/faults/compensatescope.gif"), new Label("CompensateScope"))
		};
	}	
	
	public BpelPalette(PickupDragController dragController) {
		actionGroup = new BpelItemsGroup(dragController);
		controlGroup = new BpelItemsGroup(dragController);
		faultGroup = new BpelItemsGroup(dragController);

		initPaletteItems();
		
		for (BpelControl _control : actions){
			actionGroup.add(_control);
		}
		
		for (BpelControl _control : controls){
			controlGroup.add(_control);
		}
		for (BpelControl _control : faults){
			faultGroup.add(_control);
		}
		add(actionGroup, "Actions", false);
		add(controlGroup, "Controls", false);
		add(faultGroup, "Faults", false);
		setWidth("150px");
	}
}
